function CalloutRenderItemTemplateNew(renderCtx) {
    var ret = [];

    if (renderCtx.ListSchema.IsDocLib)
        RenderSection(ret, CalloutRenderFilePreview, CalloutRenderItemTemplateCallbacks.FilePreview, renderCtx);

    RenderSection(ret, CalloutRenderLastModifiedInfo, CalloutRenderItemTemplateCallbacks.LastModifiedInfo, renderCtx);
    RenderSection(ret, CalloutRenderSharingStatus, CalloutRenderItemTemplateCallbacks.SharingStatus, renderCtx);
    RenderSection(ret, CalloutRenderSourceUrl, CalloutRenderItemTemplateCallbacks.SourceUrl, renderCtx);

    return ret.join('');
}

var CalloutRenderItemTemplateCallbacks =
{
    FilePreview: {
        renderSection: true
    },

    LastModifiedInfo: {
        renderSection: true
    },

    SharingStatus: {
        renderSection: true
    },

    SourceUrl: {
        renderSection: true
    }
}

function ReplaceCalloutRenderItemTemplate()
{
    SPClientTemplates._defaultTemplates['Item'].default.all.Callout.__DefaultTemplate__ = CalloutRenderItemTemplateNew;
}

function RenderSection(ret, originalRenderCallback, renderCallBacks, renderCtx)
{
    if (renderCallBacks['renderSection'] != true)
        return;

    if (renderCallBacks)
        ret.push(GetCalloutBodySectionHtml(renderCallBacks['Before'], renderCtx));

    ret.push(originalRenderCallback(renderCtx));

    if (renderCallBacks)
        ret.push(GetCalloutBodySectionHtml(renderCallBacks['After'], renderCtx));
}

function GetCalloutBodySectionHtml(sectionBodyCallback, renderCtx)
{
    if (sectionBodyCallback)
    {
        var bodySectionHtml = sectionBodyCallback(renderCtx);
        return '<div class="js-callout-bodySection">' + bodySectionHtml + '</div>';    
    }
    else
        return '';
     
}

_spBodyOnLoadFunctionNames.push("ReplaceCalloutRenderItemTemplate");
